package com.zygh.interactiveplatform.module.controller;


import com.alibaba.fastjson.JSONObject;
import com.zygh.interactiveplatform.common.anno.OperateLog;
import com.zygh.interactiveplatform.common.anno.PcLog;
import com.zygh.interactiveplatform.common.constant.SwaggerTagConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.User;
import com.zygh.interactiveplatform.module.entity.vo.UserPasswordVo;
import com.zygh.interactiveplatform.module.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lee
 * @since 2021-01-28
 */
@RestController
@RequestMapping("/user")
@Api(tags = {SwaggerTagConst.Admin.MANAGER_USER})
@OperateLog
public class UserController {
    @Resource
    private UserService userService;

    @ApiOperation(value = "添加员工")
    @PostMapping("/addUser")
    @PcLog(logType = "2",module = SwaggerTagConst.Admin.MANAGER_USER,content = "添加员工")
    public ResponseDTO addUser(@RequestBody @Valid User user) {
        return userService.addUser(user);
    }

    @ApiOperation(value = "修改密码")
    @PostMapping("/updatePwd")
    @PcLog(logType = "3",module = SwaggerTagConst.Admin.MANAGER_USER,content = "修改密码")
    public ResponseDTO<String> updatePwd(@Valid @RequestBody UserPasswordVo updatePwd) {
        return userService.updatePwd(updatePwd);
    }

    @ApiOperation(value = "查询所有人员信息")
    @GetMapping("/findUserAll")
    @PcLog(logType = "1",module = SwaggerTagConst.Admin.MANAGER_USER,content = "查询所有人员信息")
    public ResponseDTO<String> findUserAll(Integer current, Integer size) {
        return userService.findUserAll(current,size);
    }

    @ApiOperation(value = "修改人员信息")
    @PostMapping("/updatUserById")
    @PcLog(logType = "3",module = SwaggerTagConst.Admin.MANAGER_USER,content = "修改人员信息")
    public ResponseDTO<String> updatUserById(@RequestBody @Valid User user) {
        return userService.updatUserById(user);
    }

    @ApiOperation(value = "删除人员信息")
    @PostMapping("/deletUserById")
    @PcLog(logType = "4",module = SwaggerTagConst.Admin.MANAGER_USER,content = "删除人员信息")
    public ResponseDTO<String> deletUserById(@RequestBody String id) {
        String s = JSONObject.parseObject(id).get("id").toString();
        Integer new_id = Integer.parseInt(s);
        return userService.deletUserById(new_id);
    }


}
